<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>typedpubsub.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_pubsub_typedpubsub.js.html">typedpubsub.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2014 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.pubsub.TypedPubSub&#39;);
<a name="line16"></a>
<a name="line17"></a>goog.require(&#39;goog.Disposable&#39;);
<a name="line18"></a>goog.require(&#39;goog.pubsub.PubSub&#39;);
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>/**
<a name="line23"></a> * This object is a temporary shim that provides goog.pubsub.TopicId support
<a name="line24"></a> * for goog.pubsub.PubSub.  See b/12477087 for more info.
<a name="line25"></a> * @constructor
<a name="line26"></a> * @extends {goog.Disposable}
<a name="line27"></a> */
<a name="line28"></a>goog.pubsub.TypedPubSub = function() {
<a name="line29"></a>  goog.pubsub.TypedPubSub.base(this, &#39;constructor&#39;);
<a name="line30"></a>
<a name="line31"></a>  this.pubSub_ = new goog.pubsub.PubSub();
<a name="line32"></a>  this.registerDisposable(this.pubSub_);
<a name="line33"></a>};
<a name="line34"></a>goog.inherits(goog.pubsub.TypedPubSub, goog.Disposable);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>/**
<a name="line38"></a> * See {@code goog.pubsub.PubSub.subscribe}.
<a name="line39"></a> * @param {!goog.pubsub.TopicId.&lt;PAYLOAD&gt;} topic Topic to subscribe to.
<a name="line40"></a> * @param {function(this:CONTEXT, PAYLOAD)} fn Function to be invoked when a
<a name="line41"></a> *     message is published to the given topic.
<a name="line42"></a> * @param {CONTEXT=} opt_context Object in whose context the function is to be
<a name="line43"></a> *     called (the global scope if none).
<a name="line44"></a> * @return {number} Subscription key.
<a name="line45"></a> * @template PAYLOAD, CONTEXT
<a name="line46"></a> */
<a name="line47"></a>goog.pubsub.TypedPubSub.prototype.subscribe = function(topic, fn, opt_context) {
<a name="line48"></a>  return this.pubSub_.subscribe(topic.toString(), fn, opt_context);
<a name="line49"></a>};
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * See {@code goog.pubsub.PubSub.subscribeOnce}.
<a name="line54"></a> * @param {!goog.pubsub.TopicId.&lt;PAYLOAD&gt;} topic Topic to subscribe to.
<a name="line55"></a> * @param {function(this:CONTEXT, PAYLOAD)} fn Function to be invoked once and
<a name="line56"></a> *     then unsubscribed when a message is published to the given topic.
<a name="line57"></a> * @param {CONTEXT=} opt_context Object in whose context the function is to be
<a name="line58"></a> *     called (the global scope if none).
<a name="line59"></a> * @return {number} Subscription key.
<a name="line60"></a> * @template PAYLOAD, CONTEXT
<a name="line61"></a> */
<a name="line62"></a>goog.pubsub.TypedPubSub.prototype.subscribeOnce = function(
<a name="line63"></a>    topic, fn, opt_context) {
<a name="line64"></a>  return this.pubSub_.subscribeOnce(topic.toString(), fn, opt_context);
<a name="line65"></a>};
<a name="line66"></a>
<a name="line67"></a>
<a name="line68"></a>/**
<a name="line69"></a> * See {@code goog.pubsub.PubSub.unsubscribe}.
<a name="line70"></a> * @param {!goog.pubsub.TopicId.&lt;PAYLOAD&gt;} topic Topic to unsubscribe from.
<a name="line71"></a> * @param {function(this:CONTEXT, PAYLOAD)} fn Function to unsubscribe.
<a name="line72"></a> * @param {CONTEXT=} opt_context Object in whose context the function was to be
<a name="line73"></a> *     called (the global scope if none).
<a name="line74"></a> * @return {boolean} Whether a matching subscription was removed.
<a name="line75"></a> * @template PAYLOAD, CONTEXT
<a name="line76"></a> */
<a name="line77"></a>goog.pubsub.TypedPubSub.prototype.unsubscribe = function(
<a name="line78"></a>    topic, fn, opt_context) {
<a name="line79"></a>  return this.pubSub_.unsubscribe(topic.toString(), fn, opt_context);
<a name="line80"></a>};
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>/**
<a name="line84"></a> * See {@code goog.pubsub.PubSub.unsubscribeByKey}.
<a name="line85"></a> * @param {number} key Subscription key.
<a name="line86"></a> * @return {boolean} Whether a matching subscription was removed.
<a name="line87"></a> */
<a name="line88"></a>goog.pubsub.TypedPubSub.prototype.unsubscribeByKey = function(key) {
<a name="line89"></a>  return this.pubSub_.unsubscribeByKey(key);
<a name="line90"></a>};
<a name="line91"></a>
<a name="line92"></a>
<a name="line93"></a>/**
<a name="line94"></a> * See {@code goog.pubsub.PubSub.publish}.
<a name="line95"></a> * @param {!goog.pubsub.TopicId.&lt;PAYLOAD&gt;} topic Topic to publish to.
<a name="line96"></a> * @param {PAYLOAD} payload Payload passed to each subscription function.
<a name="line97"></a> * @return {boolean} Whether any subscriptions were called.
<a name="line98"></a> * @template PAYLOAD
<a name="line99"></a> */
<a name="line100"></a>goog.pubsub.TypedPubSub.prototype.publish = function(topic, payload) {
<a name="line101"></a>  return this.pubSub_.publish(topic.toString(), payload);
<a name="line102"></a>};
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * See {@code goog.pubsub.PubSub.clear}.
<a name="line107"></a> * @param {!goog.pubsub.TopicId.&lt;PAYLOAD&gt;=} opt_topic Topic to clear (all topics
<a name="line108"></a> *     if unspecified).
<a name="line109"></a> * @template PAYLOAD
<a name="line110"></a> */
<a name="line111"></a>goog.pubsub.TypedPubSub.prototype.clear = function(opt_topic) {
<a name="line112"></a>  this.pubSub_.clear(goog.isDef(opt_topic) ? opt_topic.toString() : undefined);
<a name="line113"></a>};
<a name="line114"></a>
<a name="line115"></a>
<a name="line116"></a>/**
<a name="line117"></a> * See {@code goog.pubsub.PubSub.getCount}.
<a name="line118"></a> * @param {!goog.pubsub.TopicId.&lt;PAYLOAD&gt;=} opt_topic The topic (all topics if
<a name="line119"></a> *     unspecified).
<a name="line120"></a> * @return {number} Number of subscriptions to the topic.
<a name="line121"></a> * @template PAYLOAD
<a name="line122"></a> */
<a name="line123"></a>goog.pubsub.TypedPubSub.prototype.getCount = function(opt_topic) {
<a name="line124"></a>  return this.pubSub_.getCount(
<a name="line125"></a>      goog.isDef(opt_topic) ? opt_topic.toString() : undefined);
<a name="line126"></a>};
</pre>


</body>
</html>
